<?php
defined('IN_ADMIN') or exit('No permission resources.');
include $this->admin_tpl('header');?>


<div class="table-list pad-lr-10">
<form name="searchform" action="" method="get">
<input type="hidden" value="admin" name="m">
<input type="hidden" value="order" name="c">
<input type="hidden" value="init" name="a">
<table width="100%" cellspacing="0" class="search-form">
    <tbody>
		<tr>
		<td>
		<div class="explain-col">
				
				订单时间：
				<?php echo form::date('start_time', $start_time)?>-
				<?php echo form::date('end_time', $end_time)?>						
				<select name="status">
					<option value="" selected="">订单状态</option>
					<option value="0">进行中</option>
					<option value="1" <?php if(isset($_GET['status']) && $_GET['status']==1){?>selected<?php }?>>已完成</option>
					<option value="2"<?php if(isset($_GET['status']) && $_GET['status']==2){?>selected<?php }?>>到店半小时</option>
					<option value="-1" <?php if(isset($_GET['status']) && $_GET['status']==-1){?>selected<?php }?>>客户取消</option>
					<option value="-2" <?php if(isset($_GET['status']) && $_GET['status']==-2){?>selected<?php }?>>商家取消</option>
				</select>	
				<select name="goodtype"><option value="" selected="">商品类型</option>
						<option value="day" <?php if(isset($_GET['goodtype']) && $_GET['goodtype']=='day'){?>selected<?php }?>>全日房</option>
						<option value="time" <?php if(isset($_GET['goodtype']) && $_GET['goodtype']=='time'){?>selected<?php }?>>小时房</option>
						<option value="goods"  <?php if(isset($_GET['goodtype']) && $_GET['goodtype']=='goods'){?>selected<?php }?>>商品</option>
				</select>
				<select name="type">
					<option value="" selected="">搜索类型</option>
					<option value="1" <?php if(isset($_GET['type']) && $_GET['type']==1){?>selected<?php }?>>用户ID</option>
					<option value="2" <?php if(isset($_GET['type']) && $_GET['type']==2){?>selected<?php }?>>商家ID</option>
					<option value="3" <?php if(isset($_GET['type']) && $_GET['type']==3){?>selected<?php }?>>预约人</option>
					<option value="4" <?php if(isset($_GET['type']) && $_GET['type']==4){?>selected<?php }?>>订单ID</option>
					<option value="5" <?php if(isset($_GET['type']) && $_GET['type']==5){?>selected<?php }?>>商品名</option>
				</select>
				<input name="keyword" type="text" value="<?php if(isset($_GET['keyword'])) {echo $_GET['keyword'];}?>" class="input-text">
				<input type="submit" name="search" class="button" value="搜索">
				<?if(isset($ordertotal['SUM(price)'])){?> <span>当前订单金额合计:<? echo $ordertotal['SUM(price)']; ?>元</span><? } ?>
	</div>
		</td>
		</tr>
    </tbody>
</table>
</form>

<script type="text/javascript">
var serverTime = <? echo SYS_TIME;?> * 1000;
$(function(){
    var dateTime = new Date();
    var difference = dateTime.getTime() - serverTime;
	
    setInterval(function(){
      $(".endtime").each(function(){
        var obj = $(this);
        var endTime = new Date(parseInt(obj.attr('value')) * 1000);
        var nowTime = new Date();
        var nMS=endTime.getTime() - nowTime.getTime() + difference;
        var myD=Math.floor(nMS/(1000 * 60 * 60 * 24));
        var myH=Math.floor(nMS/(1000*60*60)) % 24;
        var myM=Math.floor(nMS/(1000*60)) % 60;
        var myS=Math.floor(nMS/1000) % 60;
        var myMS=Math.floor(nMS/100) % 10;
        if(myD>= 0){
			var str = myH+"小时"+myM+"分"+myS+"."+myMS+"秒";//myD+"天"+
        }else{
			var str = "已结束！";	
		}
		obj.html(str);
      });
    }, 100);
});
</script>
<form name="myform" action="" method="post">
    <table width="100%" cellspacing="0">
        <thead>
		<tr>
		<th width="2%"><input type="checkbox" value="" id="check_box" onclick="selectall('orderid[]');"></th>
		<th width="8%"><?php echo L('订单时间');?></th>
		<th width="5%">订单ID</th>
		<th width="2%"  align="left" ><?php echo L('用户ID');?></th>
		<th width="5%"  align="left" ><?php echo L('预约人');?></th>
		<th width="5%"  align="left" ><?php echo L('商家ID');?></th>
		<th width="5%"  align="left" ><?php echo L('预约商家');?></th>
		<th width="8%"  align="left" ><?php echo L('预约状态');?></th>
		<th width="8%"  align="left" ><?php echo L('到店时间');?></th>
		<th width="30%"  align="left" ><?php echo L('商品');?></th>
		<th width="5%"  align="left" ><?php echo L('总价');?></th>
		<th width="5%"  align="left" ><?php echo L('其它要求');?></th>
		</tr>
        </thead>
<tbody>
<?php 
if(is_array($infos)){
	foreach($infos as $info){
?>
<tr>
<td width="2%" align="center"><input type="checkbox" value="<?php echo $info['order_id']?>" name="orderid[]"></td>
<td width="8%" align="center"><?php echo date('Y-m-d H:i:s',$info['order_time']);?></td>
<td width="5%" align="center"><?php echo $info['order_id']?></td>
<td width="5%" align="center"><?php echo $info['user_id']?></td>
<td width="5%"  >
<?
 $member_db = pc_base::load_model('member_model');
/*  $member_db->set_model(10);		
 $userdata = $member_db->get_one(array('userid'=>$info['user_id'])); */
 echo $info['name'];
?>
</td>
<td width="5%" align="center"><?php echo $info['shop_id']?></td>
<td width="5%" align="center">
<?php	
  $member_db->set_model(13);	
  $shop = $member_db->get_one(array('userid'=>$info['shop_id'])); 
 echo $shop['name']?>
 </td>

<td width="8%" ><?php if($info['order_status']==0){ echo '预订中';}elseif($info['order_status']==1){ echo '已完成';}elseif($info['order_status']==2){ echo '预约到店中<div class="endtime" value="'.($info[timeshop]+1800).'"></div>';}elseif($info['order_status']==-2){ echo '商家取消';}else{ echo '客户取消';}?></td>
<td width="8%"><?php echo date('Y-m-d H:i:s',$info['timeshop']);?></td>
<td width="30%">
<? $gdaa = string2array($info['goods']);
	foreach($gdaa as $vv){	
?>
			<li>
				<!--<?if($vv[thumb]){?><img src="<? echo $vv[thumb];?>" width="75" height="75" /><?}?>-->
				<p>商品名: <? echo $vv[title];?>&nbsp;&nbsp;
				单价:<span class="pricecolor">￥<? echo $vv[price];?>元</span> &nbsp;&nbsp;
				数量:<? echo $vv[num];?> <?if($vv['goodtype']=='time'){echo '小时';}elseif($vv['goodtype']=='day'){echo '晚';}else{echo '件';}?>
				</p>
			</li>
			<? $goodtype = $vv['goodtype']?>
<? }
?>
</td>
<td width="10%"><?php echo $info['price'];?>元</td>
<td width="10%"><?php echo $info['other'];?></td>
</tr>
<?php 
	}
}
?>
</tbody>
</table>
<div class="btn">
<label for="check_box"><?php echo L('select_all')?>/<?php echo L('cancel')?></label> 
<input type="submit" class="button" name="dosubmit" value="<?php echo L('delete')?>" onclick="document.myform.action='?m=admin&c=order&a=del';return confirm('<?php echo L('确认删除吗?')?>');"/>
<input type="submit" class="button" name="dosubmit" onclick="document.myform.action='?m=admin&c=order&a=status&status=-1';" value="取消"/>
<input type="submit" class="button" name="dosubmit" onclick="document.myform.action='?m=admin&c=order&a=status&status=1';" value="完成"/>
<input type="submit" class="button" name="dosubmit" onclick="document.myform.action='?m=admin&c=order&a=status&status=0';" value="进行中"/>
</div>
<div id="pages"><?php echo $pages;?></div>
</form>
</div>
</body>
</html>
